set maxvar 10000 
use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/GSS7218_R2.DTA"



generate conmil = .
replace conmil = 0 if conarmy > 1 & conarmy < 4
replace conmil = 1 if conarmy == 1


generate PID3 = .
replace PID3 = 1 if partyid < 3
replace PID3 = 2 if partyid == 3
replace PID3 = 3 if partyid > 3 & partyid < 7

generate dem = 0
replace dem = 1 if PID3 == 1
generate rep = 0
replace rep = 1 if PID3 == 3

generate strongdem = 0
replace strongdem = 1 if partyid == 0

generate strongrep = 0
replace strongrep = 1 if partyid == 6

generate IDEO3 = .
replace IDEO3 = -1 if polviews < 4 & polviews > 0
replace IDEO3 = 0 if polviews == 4
replace IDEO3 = 1 if polviews > 4 & polviews < 8

generate white = 0
replace white = 1 if race == 1
generate black = 0
replace black = 1 if race == 2

generate man = 0
replace man = 1 if gender1 == 1
generate woman = 0
replace woman = 1 if gender1 == 2

generate income5 =.
replace income5 = 1 if realinc < 25000
replace income5 = 2 if realinc > 24999 & realinc < 50000
replace income5 = 3 if realinc > 49999 & realinc < 85000
replace income5 = 4 if realinc > 84999 & realinc < 150000
replace income5 = 5 if realinc > 149999

generate education = 0
replace education = 1 if educ == 12
replace education = 2 if educ > 12 & educ < 16
replace education = 3 if educ == 16
replace education = 4 if educ > 16

generate waryear = 0
replace waryear = 1 if year < 1976
replace waryear = 1 if year == 1991
replace waryear = 1 if year > 2000

generate dempres = 0
replace dempres = 1 if year > 1976 & year < 1981
replace dempres = 1 if year > 1992 & year < 2001
replace dempres = 1 if year > 2008 & year < 2017

generate reppres = 0
replace reppres = 1 if year < 1977
replace reppres = 1 if year > 1980 & year < 1993
replace reppres = 1 if year > 2000 & year < 2009
replace reppres = 1 if year > 2016


egen meanmil = mean(conmil), by(year)
twoway line meanmil year, sort
twoway connected meanmil year, sort

egen meandem = mean(conmil) if PID3 == 1, by(year)
egen meanrep = mean(conmil) if PID3 == 3, by(year)
egen meanind = mean(conmil) if PID3 == 2, by(year)

mean meandem if dempres == 1
mean meandem if dempres == 0
mean meanrep if reppres == 1
mean meanrep if reppres == 0

mean meanrep, over(year)
mean meandem, over(year)

egen meanlib = mean(conmil) if IDEO3 == -1, by(year)
egen meanmod = mean(conmil) if IDEO3 == 0, by(year)
egen meancon = mean(conmil) if IDEO3 == 1, by(year)

egen meanvlib = mean(conmil) if polviews == 1, by(year)
egen meanvcon = mean(conmil) if polviews == 7, by(year)

egen meanwhite = mean(conmil) if white == 1, by(year)
egen meanblack = mean(conmil) if black == 1, by(year)

egen meanman = mean(conmil) if man == 1, by(year)
egen meanwoman = mean(conmil) if woman == 1, by(year)

egen meanideodem = mean(IDEO3) if PID3 == 1, by(year)
egen meanideorep = mean(IDEO3) if PID3 == 3, by(year)
egen meanideoind = mean(IDEO3) if PID3 == 2, by(year)
twoway line meanideodem meanideorep meanideoind year
twoway line meanideodem meanideorep year

egen meaninc1 = mean(conmil) if income5 == 1, by(year)
egen meaninc2 = mean(conmil) if income5 == 2, by(year)
egen meaninc3 = mean(conmil) if income5 == 3, by(year)
egen meaninc4 = mean(conmil) if income5 == 4, by(year)
egen meaninc5 = mean(conmil) if income5 == 5, by(year)
egen meaninc15 = mean(conmil) if income5 < 3, by(year)
egen meaninc25 = mean(conmil) if income5 > 3, by(year)


tab PID3 IDEO3, row
tab PID3 IDEO3 if year == 1974, row
tab PID3 IDEO3 if year == 1978, row
tab PID3 IDEO3 if year == 2000, row
tab PID3 IDEO3 if year == 2002, row
tab PID3 IDEO3 if year == 2018, row

tab PID3 polviews, row
tab PID3 polviews if year == 1974, row
tab PID3 polviews if year == 1980, row
tab PID3 polviews if year == 2000, row
tab PID3 polviews if year == 2002, row
tab PID3 polviews if year == 2018, row

tab year conmil, row

******
twoway line meanmil year, sort yscale(range(0 .8)) ylabel(#4) xline(1991, lwidth(5) lc(gs12)) xline(2009.5, lwidth(41) lc(gs12)) xline(1975, lwidth(8) lc(gs12))

twoway (rarea meanrep meandem year), name(partydif)
twoway (rarea meancon meanlib year), named(partydif1)
graph combine partydif partydif1

twoway (rarea meanrep meandem year), name(partygraph) xline(2000, lwidth(1) lc(gs12)) xline(2002, lwidth(1) lc(gs12)) xline(2004, lwidth(1) lc(gs12)) xline(2006, lwidth(1) lc(gs12)) xline(2010, lwidth(1) lc(gs12)) xline(2012, lwidth(1) lc(gs12)) xline(2016, lwidth(1) lc(gs12))

egen meanvlib = mean(conmil) if polviews == 1, by(year)
egen meanvcon = mean(conmil) if polviews == 7, by(year)

twoway (rarea meanvcon meanvlib year), name(ideograph) xline(2000, lwidth(1) lc(gs12)) xline(2002, lwidth(1) lc(gs12)) xline(2004, lwidth(1) lc(gs12)) xline(2006, lwidth(1) lc(gs12)) xline(2010, lwidth(1) lc(gs12)) xline(2012, lwidth(1) lc(gs12)) xline(2016, lwidth(1) lc(gs12))

twoway line meandem meanrep year, sort yscale(range(0 .8)) ylabel(#4) xline(1991, lwidth(5) lc(gs12)) xline(2009.5, lwidth(41) lc(gs12)) xline(1983, lwidth(5) lc(gs12)) xline(1984, lwidth(3) lc(gs12)) xline(1975, lwidth(8) lc(gs12))

egen meanwhite = mean(conmil) if white == 1, by(year)
egen meanblack = mean(conmil) if black == 1, by(year)
twoway line meanwhite meanblack year, sort

egen meanman = mean(conmil) if man == 1, by(year)
egen meanwoman = mean(conmil) if woman == 1, by(year)
twoway line meanman meanwoman year, sort

egen meanhsorless = mean(conmil) if education < 2, by(year)
egen meancollege = mean(conmil) if education > 1 & education < 4, by(year)
egen meangraduate = mean(conmil) if education == 4, by(year)
twoway line meanhsorless meancollege meangraduate year, sort

egen meandemhsorless = mean(conmil) if education < 2 & PID3 == 1, by(year)
egen meanrephsorless = mean(conmil) if education < 2 & PID3 == 3, by(year)
egen meandemgrad = mean(conmil) if education == 4 & PID3 == 1, by(year)
egen meanrepgrad = mean(conmil) if education == 4 & PID3 == 3, by(year)
twoway line meandemhsorless meandemgrad year, name(dschool)
twoway line meanrephsorless meanrepgrad year, name(rschool)
graph combine dschool rschool


twoway (rarea meandemhs meandemgrad year), name(dschool1)
twoway (rarea meanrephs meanrepgrad year), name(rschool1)
graph combine dschool1 rschool1

egen deminc1 = mean(conmil) if income5 < 3 & PID3 == 1, by(year)
egen deminc2 = mean(conmil) if income5 > 3 & PID3 == 1, by(year)
egen repinc1 = mean(conmil) if income5 < 3 & PID3 == 3, by(year)
egen repinc2 = mean(conmil) if income5 > 3 & PID3 == 3, by(year)

twoway line deminc1 deminc2 year, sort yscale(range(0 .8)) name(dinc)
twoway line repinc1 repinc2 year, sort yscale(range(0 .8)) name(rinc)
graph combine dinc rinc

generate generation = .
replace generation = 0 if cohort < 1928
replace generation = 1 if cohort > 1927 & cohort < 1946
replace generation = 2 if cohort > 1946 & cohort < 1965
replace generation = 3 if cohort > 1964 & cohort < 1980
replace generation = 4 if cohort > 1979 & cohort < 1997
replace generation = 5 if cohort > 1996

generate boomer = 0
replace boomer = 1 if generation == 2
generate genx = 0
replace genx = 1 if generation == 3
generate millen = 0
replace millen = 1 if generation == 4
generate genz = 0
replace genz = 1 if generation == 5

generate post911 = 0
replace post911 = 1 if year > 2000


generate region4 =.
replace region4 = 1 if region < 3
replace region4 = 2 if region > 2 & region < 5
replace region4 = 3 if region > 4 & region < 8
replace region4 = 4 if region > 7

egen meanNE = mean(conmil) if region4 == 1, by(year)
egen meanMW = mean(conmil) if region4 == 2, by(year)
egen meanSOUTH = mean(conmil) if region4 == 3, by(year)
egen meanWEST = mean(conmil) if region4 == 4, by(year)
twoway line meanNE meanMW meanSOUTH meanWEST year

generate clinton = 0
replace clinton = 1 if year > 1992 & year < 2001
generate obama = 0
replace obama = 1 if year > 2008 & year < 2017

egen meangreat = mean(conmil) if generation == 0, by(year)
egen meansilent = mean(conmil) if generation == 1, by(year)
egen meanboomer = mean(conmil) if generation == 2, by(year)
egen meangenx = mean(conmil) if generation == 3, by(year)
egen meanmillen = mean(conmil) if generation == 4, by(year)
egen meangenz = mean(conmil) if generation == 5, by(year)

twoway line meansilent meanboomer meangenx meanmillen year if year > 1995

twoway line meaninc1 meaninc5 year, sort

xi I.reppres*I.rep, prefix(_I)
ologit conarmy dem strongdem rep strongrep IDEO3 education black man waryear boomer genx millen genz realinc south reppres _IrepXrep_1_1 _IrepXstr_1_1

reg conarmy dem strongdem rep strongrep IDEO3 education black man waryear boomer genx millen genz realinc south reppres _IrepXrep_1_1 _IrepXstr_1_1

predict conarmy235234_predict

adjust man=1 dem=1 strongdem=0 rep=0 strongrep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=0 _IrepXrep_1_1=0 _IrepXstr_1_1=0
adjust man=1 dem=1 strongdem=0 rep=0 strongrep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=1 _IrepXrep_1_1=0 _IrepXstr_1_1=0
adjust man=1 dem=1 strongdem=1 rep=0 strongrep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=0 _IrepXrep_1_1=0 _IrepXstr_1_1=0
adjust man=1 dem=1 strongdem=1 rep=0 strongrep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=1 _IrepXrep_1_1=0 _IrepXstr_1_1=0

adjust man=1 dem=0 strongdem=0 rep=1 strongrep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=0 _IrepXrep_1_1=0 _IrepXstr_1_1=0
adjust man=1 dem=0 strongdem=0 rep=1 strongrep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=1 _IrepXrep_1_1=1 _IrepXstr_1_1=0
adjust man=1 dem=0 strongdem=0 rep=1 strongrep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=0 _IrepXrep_1_1=0 _IrepXstr_1_1=0
adjust man=1 dem=0 strongdem=0 rep=1 strongrep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=1 _IrepXrep_1_1=1 _IrepXstr_1_1=1



logit conmil dem rep IDEO3 education black man waryear boomer genx millen genz realinc south post911 reppres _IrepXrep_1_1

predict conmil1_predict
adjust man=1 dem=1 rep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=0 _IrepXrep_1_1=0
adjust man=1 dem=1 rep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=1 _IrepXrep_1_1=0

adjust man=1 dem=0 rep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=0 _IrepXrep_1_1=0
adjust man=1 dem=0 rep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 reppres=1 _IrepXrep_1_1=1

adjust man=1 dem=1 rep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=0 reppres=0 _IrepXrep_1_1=0
adjust man=1 dem=1 rep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=0 reppres=1 _IrepXrep_1_1=0

adjust man=1 dem=0 rep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=0 reppres=0 _IrepXrep_1_1=0
adjust man=1 dem=0 rep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=0 reppres=1 _IrepXrep_1_1=1

adjust man=1 dem=1 rep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=1 reppres=0 _IrepXrep_1_1=0
adjust man=1 dem=1 rep=0 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=1 reppres=1 _IrepXrep_1_1=0

adjust man=1 dem=0 rep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=1 reppres=0 _IrepXrep_1_1=0
adjust man=1 dem=0 rep=1 IDEO3=0 black=0 waryear=0 boomer=0 genx=1 millen=0 genz=0 south=0 post911=1 reppres=1 _IrepXrep_1_1=1



reg conarmy dem rep IDEO3 education black man waryear boomer genx millen genz realinc south


generate ownparty = 0
replace ownparty = 1 if PID3 == 3 & year < 1977
replace ownparty = 1 if PID3 == 1 & year > 1976 & year < 1981
replace ownparty = 1 if PID3 == 3 & year > 1979 & year < 1993
replace ownparty = 1 if PID3 == 1 & year > 1992 & year < 2001
replace ownparty = 1 if PID3 == 3 & year > 2000 & year < 2009
replace ownparty = 1 if PID3 == 1 & year > 2008 & year < 2017
replace ownparty = 1 if PID3 == 3 & year > 2016

I.ownparty*I.dem I.ownparty*I.rep, prefix(_I)

reg conarmy dem rep IDEO3 education black man waryear boomer genx millen genz realinc south ownparty _IownXdem_1_1 _IownXrep_1_1

ologit conarmy dem rep IDEO3 education black man waryear boomer genx millen genz realinc south ownparty _IownXdem_1_1 _IownXrep_1_1

logit conmil dem rep IDEO3 education black man waryear boomer genx millen genz realinc south ownparty _IownXdem_1_1 _IownXrep_1_1
